package com.set;

import java.util.HashSet;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-12-19
 * Time: 11:22
 */
public class TestDemo2 {
    public static void main(String[] args) {
        HashSet<String> set = new HashSet();
        //添加
        set.add("aaa");
        set.add("bbb");
        set.add("ccc");
        set.add("aaa");//不会添加进去，set不重复
        //遍历
        for(String s : set){
            System.out.println(s+" ");
        }

        System.out.println(set.size());

        //是否包含
        if(set.contains("ddd")){
            System.out.println("Y");
        }else{
            System.out.println("N");
        }
        System.out.println(set.contains("ddd") ? "Y" : "N");
        Iterator<String> it = set.iterator();
        while(it.hasNext()){
            String s = it.next();
            System.out.print(s+" ");
        }
        System.out.println();
    }
}
